#define MAX_NODE_SIZE 10000

void helper(const struct Node* root, int* res, int* pos) {
    if (NULL == root) {
        return;
    }
    res[(*pos)++] = root->val;
    for (int i = 0; i < root->numChildren; i++) {
        helper(root->children[i], res, pos);
    }
}

int* preorder(struct Node* root, int* returnSize) {
    int* res = (int*)malloc(sizeof(int) * MAX_NODE_SIZE);
    int pos = 0;
    helper(root, res, &pos);
    *returnSize = pos;
    return res;
}